﻿package zf.media.audio.spectrum
{
	import flash.display.Sprite;
	import flash.filters.BlurFilter;
	import flash.filters.GlowFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	
	import zf.data.geom.plan.RegularStar;
	import zf.media.audio.SoundSpectrumMode;

	/**
	 * 星型声谱图形 
	 * @author mike.zhang
	 * 
	 */
	public class StarSpectrum extends SoundSpectrum
	{
		private var vmin:Number;
		private var side:uint;
		private var jd:Number;
		private var rmin:Number;
		private var randomCt2:ColorTransform;
		
		private var dx:Number;
		private var dy:Number;
		private var a:Number;
		private var aa:Number;
		private var max:Number;

		private var star:RegularStar;
		private var lineSprite:Sprite;
		/**
		 * 创建一个星型声谱 
		 * @param w 宽度
		 * @param h 高度
		 * 
		 */
		public function StarSpectrum (w:Number,h:Number):void
		{
			super (w,h);
			type=SoundSpectrumMode.SS;
			ff=1;
			jd=0;
			abs=true;
			machining=true;
			vmin=ww>hh?hh:ww;
			vmin*=0.25;
			randomCt2=getCt();
			lineSprite=new Sprite;
			side=Math.round(Math.random()*5)*2+3;
			
			a=Math.PI*2*Math.random();
			aa=Math.random()>0.5?-0.002:0.002;
			max=w>h?w:h;
			max=max>60?2:max/30;
			dy=Math.sin(a)*max;
			dx=Math.cos(a)*max;
			//lineSprite.graphics.lineStyle(1,randomCt.color);
			//lineSprite.filters=new Array(new GlowFilter(getCt().color,1,4,4,4));
		}
		/**
		 * @private 
		 * 
		 */
		override protected function draw ():void
		{
			super.draw ();
			//dy=Math.sin(a)*max*10;
			//dx=Math.cos(a)*max*10;
			//a+=aa;
			
			rmin=byArr[0]*vmin;
			side=Math.round(byArr[0]*5)*2+3;
			//此处需要用图形来绘制，不能用星形
			
			lineSprite.graphics.clear();
			star=new RegularStar(side,rmin+2,rmin*2+5);
			lineSprite.graphics.lineStyle(1,randomCt.color);
			star.draw(lineSprite,ww*0.5,hh*0.5,jd);
			
			//lineSprite=new RStarSprite(ww*0.5,hh*0.5,side,rmin+2,rmin*2+5,jd*180/Math.PI,randomCt.color,1,1,false);
			lineSprite.filters=new Array(new GlowFilter(randomCt2.color,1,4,4,4));
			//lineSprite.x=ww/2;
			//lineSprite.y=hh/2;
			//trace(lineSprite);
			//lineSprite.addChild(star);

			//bgData:BitmapData=_bg.bitmapData;
			_bg.bitmapData.draw (lineSprite,null,null,_blendMode);
			_bg.bitmapData.applyFilter (_bg.bitmapData,_bg.bitmapData.rect,new Point(),new BlurFilter(2,2,1));
			//_bg.bitmapData.applyFilter (_bg.bitmapData,_bg.bitmapData.rect,new Point(),new GlowFilter(randomCt2.color,1,4,4,4));
			_bg.bitmapData.colorTransform (_bg.bitmapData.rect,new ColorTransform(1, 1, 1, 1, -5, -10, -10));
			_bg.bitmapData.scroll (dx,dy);
			jd+=0.2;
		}
		private function creatV ():Number
		{
			return vmin * 0.003 * Math.random();
		}
		
		override public function defaultConfig():void
		{
			abs=true;
			machining=true;
		}
	}
}